package com.apes.scm.masterdata.party.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.party.model.Party;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Map;

public interface SupplierRepository extends CustomRepository<Party, Long> {
    @Query(" SELECT T FROM Party T JOIN T.partyRoles F  " +
            "WHERE F.role.id = :roleType AND (F.id LIKE :value OR T.name LIKE :value) ")
    Page<Party> find(@Param("roleType") String roleType, @Param("value") String value, Pageable pageable);

    @Query("SELECT new map(T.id as id,T.name as name) from Party T JOIN T.partyRoles F where 1=1 and T.partyType='corporate' and F.role.id = 'Supplier' and (T.name LIKE %:value%)")
    Page<Map<String,String>> findByKeyAndCompany(@Param("value") String value, Pageable pageable);
}
